import time
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import threading

desired_caps = {'platformName': 'Android', 'platformVersion': '9', 'deviceName': '192.168.2.107:5555',
                'appPackage': 'com.seven.qaml.burstserven',
                'appActivity': 'com.seven.qaml.burstserven.ui.LoginActivity', 'automationName': 'Uiautomator2',
                'noReset': True}

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
time.sleep(1)
driver.find_element(By.ID, "com.seven.qaml.burstserven:id/btn_info").click()
# time.sleep(1)
# # driver.find_element(By.ID, "com.seven.qaml.burstserven:id/button1").click()
time.sleep(1)
driver.find_element(By.XPATH,
                    "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout"
                    "/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android"
                    ".widget.LinearLayout[2]").click()
time.sleep(1)
driver.find_element(By.ID, "com.seven.qaml.burstserven:id/id_tv_zuwang").click()

# # 扫描
# element_boom = WebDriverWait(driver, 30).until(
#     EC.presence_of_element_located((By.ID, "com.seven.qaml.burstserven:id/tv_burstBoom_start")))
# element_boom.click()
# # 验证
# time.sleep(2)
# driver.find_element(By.ID, "com.seven.qaml.burstserven:id/tv_burstBoomAuth_start").click()
# # 验证完成
# time.sleep(2)
# driver.find_element(By.ID, "com.seven.qaml.burstserven:id/tv_burstBoom_endAuth").click()
# # 充电
# driver.press_keycode(300)
# # 起爆
# time.sleep(35)
# # adb_command = "adb shell input keyevent 132 && adb shell input keyevent 999"
# # driver.execute_script('mobile: shell', {'command': adb_command})
# def press_key_999():
#     driver.press_keycode(999)
# def press_key_132():
#     driver.press_keycode(132)
# # 创建两个线程
# thread_999 = threading.Thread(target=press_key_999)
# thread_132 = threading.Thread(target=press_key_132)
# # 启动线程
# thread_999.start()
# thread_132.start()
# # 等待线程完成
# thread_999.join()
# thread_132.join()
# time.sleep(3)